function A3cOut = seaMountMap(A1cIn,OptBlue)
%seaMountMap - Geo map with sea and mounts
%
%       A3cOut = seaMountMap(A1cIn,OptBlue)
%
% This function provides the RGB color image (as a 3D array) A3cOut
% starting from the 1-channel input image A1cIn related to a DTM in
% such a way that the sea (A1cIn <= 0) is in blue. 
% If OptBlue is 'light' or 'dark', the sea is in light blue or dark blue
% respectively. If OptBlue is undefined, empty or is neither 'light' nor
% 'dark', the default option OptBlue = 'ligth' is used.
%
% This function calls customcolormap by Víctor Martínez-Cagigal, Biomedical 
% Engineering Group (University of Valladolid), Spain (download page:
% https://it.mathworks.com/matlabcentral/fileexchange/69470-custom-colormap)
%
% See also gs_GenDTMImage.

% G. Teza, 2022

if (nargin < 2) || isempty(OptBlue) || ~ismember(OptBlue,{'light','dark'}) 
    BlueVec = [171,205,239];
elseif strcmp(OptBlue,'light')
    BlueVec = [171,205,239];
else
    BlueVec = [61,139,214];
end

% external function by Víctor Martínez-Cagigal:
J = customcolormap([0 1],{'#EFEFEF','#5F5F5F'}); 

I = A1cIn <= 0;

Anew = double(A1cIn);
Am = uint8(255*(Anew-min(Anew(:)))/(max(Anew(:))-min(Anew(:))));
A3Dv = ind2rgb(imcomplement(Am),J);
A3Dv = uint8(255*A3Dv);

A3cOut = colorImPixel(A3Dv,I,BlueVec);

%% ANCILLARY FUNCTIONS

function Imm = colorImPixel(Im,Ipix,ColVec)
%colorImPixel - coloring selected pixels of an image
%
%   Imm = colorImPixel(Im,Ipix,ColVec)
%
% Input arguments:
%   Im    : input RGB image
%   Ipix  : indices of image pixels to be colored
%   ColVec: RGB color vector (for example, ColVec = [171,205,239] in the
%           case of ligthblue) 
%
% Output:
%   Imm   : output RGB image 

R = Im(:,:,1);
G = Im(:,:,2);
B = Im(:,:,3);

Rm = R;
Rm(Ipix) = ColVec(1);
Gm = G;
Gm(Ipix) = ColVec(2);
Bm = B;
Bm(Ipix) = ColVec(3);

Imm = cat(3,Rm,Gm,Bm);